﻿using CommunityToolkit.Mvvm.Messaging;
using myfirstmaui.Pages;
using myfirstmaui.ViewModels;
using System.Reflection;

namespace myfirstmaui
{
    //每个平台都不一样...
    //ControlTemplate的基本概念和用途
    //ControlTemplate定义了控件的视觉表示，包括其布局、颜色、大小等。通过使用ControlTemplate，开发者可以重用模板，而不是为每个控件编写相同的布局和样式代码。这有助于减少重复代码，提高开发效率‌
    public partial class MainPage : ContentPage
    {
        int count = 0;

        public MainPage()
        {
            
            //注册消息..(必须在前面..)
            WeakReferenceMessenger.Default.Register<string, string>(this, "ShowError", ShowError);                
            InitializeComponent();
        }

        private async void ShowError(object recipient, string message)
        {
            await DisplayAlert("错误", message, "点击继续");
            return;
        }

        private void RadioButton_CheckedChanged(object sender, CheckedChangedEventArgs e)
        {            
            if (e.Value)
            {
                var button = sender as RadioButton;
                if (button.BindingContext.ToString() == "")
                {

                }
                //string mytype = "myfirstmaui.Page." + button.BindingContext.ToString();
                //Type type = Assembly.GetExecutingAssembly().GetType(mytype);
                //Type type = Assembly.GetExecutingAssembly().GetType("myfirstmaui.Pages." + button.BindingContext.ToString());
                //this.MainFrame.Content = (View)Activator.CreateInstance(type);
                //this.MainFrame.Content = new MyPage1();
            }
            else
            {
                //this.MainFrame.Content = null;
            }
        }

    }

}
